home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Printing Samples / Printer Drivers… / LaserWriterIISC / ChooserSupport.c < prev    next >
Encoding:
Text File  |  1993-09-13  |  8.4 KB  |  301 lines  |  [TEXT/MPS ]

  1. /*---------------------------------------------------------------------------
  2. FILENAME
  3.     ChooserSupport.c
  4.  
  5. DESCRIPTION
  6.     This file contains the C code for the PACK and LDEF routines used by the
  7.     Chooser when the LaserWriter IISC driver is selected in the Chooser.
  8.         
  9.     9/13/93 - dmh - Updated for the b2 seed.
  10.         
  11. COPYRIGHT
  12.     Copyright Apple Computer, Inc. 1992
  13.     All rights reserved. 
  14.     
  15. INTERFACE ROUTINES:
  16.     Device
  17.     LDEF
  18.  
  19. -------------------------------------------------------------------------------- */
  20.  
  21. // Include the standard Mac header files 
  22. #include "MacIncludes.h"
  23.  
  24. // Include the new QuickDraw GX graphics header files 
  25. #include <graphics routines.h>
  26.  
  27. // Include the required Printing Manager header files 
  28. #include <PrintingDrivers.h>
  29.  
  30. /*********************************************************************************
  31.  *                                         CONSTANTS                                                     *
  32.  *********************************************************************************/
  33.  
  34. // Chooser initialize message selector
  35. #define    initializeMsg            11
  36.  
  37. // Icon Suite support
  38.  
  39. #define    ttNone                    0x0000
  40. #define    ttDisabled                0x0001
  41. #define    ttOffline                0x0002
  42. #define    ttOpen                    0x0003
  43. #define    ttSelected                 0x4000
  44. #define    ttSelectedDisabled        (ttSelected + ttDisabled)
  45. #define    ttSelectedOffline        (ttSelected + ttOffline)
  46. #define    ttSelectedOpen            (ttSelected + ttOpen)
  47.  
  48. #define    ttLabel0                    0x0000
  49. #define    ttLabel1                    0x0100
  50. #define    ttLabel2                    0x0200
  51. #define    ttLabel3                    0x0300
  52. #define    ttLabel4                    0x0400
  53. #define    ttLabel5                    0x0500
  54. #define    ttLabel6                    0x0600
  55. #define    ttLabel7                    0x0700
  56.  
  57.  
  58. /*********************************************************************************
  59.  *                                    INLINE DECLARATIONS                                            *
  60. **********************************************************************************/
  61.  
  62. pascal OSErr PlotIconSuite(const Rect * theRect, short align, short iconTransform, Handle cIcon)
  63.     = {0x303C, 0x0603, 0xABC9};
  64.  
  65. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  66.     = 0xA885; 
  67.  
  68.  
  69. /***************************************************************************************
  70. *                                         INTERFACE ROUTINES                                                     *
  71. ***************************************************************************************/                        
  72.  
  73.  
  74. /****************************************************************************************
  75.  
  76.                             Device
  77.                             
  78.     function:
  79.                 This routine is the interface routine for the Chooser PACK.  This is the
  80.                 routine the Chooser calls to perform the Chooser functions for the 
  81.                 LaserWriter IISC driver.
  82.                 
  83.     parameters:                
  84.                 message        specifies which Chooser function to perform    
  85.                 caller        equals 1; specifies the caller is the Chooser
  86.                 objName        name of the selected device
  87.                 zoneName    zone name for AppleTalk devices
  88.                 theList        the list of names
  89.                 p2            parameter used depending upon message value
  90.                 
  91.     returns:
  92.                 OSErr
  93.     
  94. ****************************************************************************************/
  95. pascal OSErr Device(    short         message, 
  96.                         short         caller, 
  97.                         StringPtr     objName,
  98.                         StringPtr    zoneName, 
  99.                         ListHandle    theList, 
  100.                         long        p2)
  101. {
  102.     
  103.     OSErr            anErr = noErr;
  104.     extern Str31    gDriverName;
  105.     extern gxJob    gJob;
  106.     StringPtr        pDriverName = &gDriverName;
  107.     gxJob            *pJob = &gJob;
  108.     
  109.     if (message == initializeMsg)        //    T => Chooser PACK should initialize itself; start up QuickDraw GX 
  110.     {
  111.         FCBPBRec    pb;
  112.  
  113.         // determine the name of the driver selected
  114.         pb.ioCompletion     = nil;
  115.         pb.ioNamePtr         = pDriverName;
  116.         pb.ioVRefNum         = 0;
  117.         pb.ioRefNum         = CurResFile();
  118.         pb.ioFCBIndx         = 0;
  119.         anErr = PBGetFCBInfo(&pb, false);
  120.  
  121.         // Now initialize QuickDraw GX
  122.         *pJob = nil;
  123.         if (anErr == noErr)
  124.         {
  125.             GXEnterGraphics();
  126.             anErr = GXGetGraphicsError(nil);
  127.             if (anErr == noErr)
  128.                 anErr = GXInitPrinting();
  129.         }
  130.     }
  131.         
  132.     // We let the system handle the device choosing for us
  133.     if (anErr == noErr)
  134.         anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  135.         
  136.     // Is it time to go away?
  137.     if ( (message == terminateMsg) && (p2 == terminateMsg) )
  138.     {
  139.         GXExitPrinting();
  140.         GXExitGraphics();
  141.     }
  142.  
  143.     return(anErr);
  144. }
  145. /* Device */
  146.  
  147.  
  148.  
  149. /****************************************************************************************
  150.  
  151.                             LDEF
  152.                             
  153.     function:
  154.                 This routine is the LDEF fro the Chooser PACK.  It handles drawing the device
  155.                 list contents.  The LDEF works in two modes:
  156.                     - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
  157.                       then the LDEF is just a basic text LDEF
  158.                     - otherwise, it assumes the data is part of a PortListRec, which is
  159.                       a structure for icons with text underneath
  160.                             
  161.     parameters:                
  162.                 message        what operation to perform on the list    
  163.                 select        is this cell to be selected or not?
  164.                 theRect        rectangle of this cell, clipped to window
  165.                 theCell        which cell this is
  166.                 dataOffset    offset into data for this cell
  167.                 dataLen        length of data for this cell
  168.                 theList        the list to act upon
  169.                 
  170.     returns:
  171.                 None
  172.     
  173. ****************************************************************************************/
  174. pascal void LDEF(
  175.     short             message,
  176.     Boolean            select,
  177.     Rect            *theRect,
  178.     Cell            theCell,
  179.     short            dataOffset,
  180.     short            dataLen,
  181.     ListHandle        theList)
  182. {
  183.     #pragma unused (theCell, dataLen)
  184.  
  185.     gxPortListRec    theCellContents;
  186.     Rect            iconRect;
  187.     
  188.     switch (message)
  189.     {
  190.         case lDrawMsg:
  191.         case lHiliteMsg:
  192.         
  193.             // save the data to avoid locking things down
  194.             if (dataLen > sizeof(theCellContents) )
  195.                 dataLen = sizeof(theCellContents);
  196.             BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
  197.             
  198.             // draw the cell as an icon, but only if we see our magic marker at the front
  199.             if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
  200.             {
  201.                 // center the icon rect on the list with a top margin of 10 pixels
  202.                 iconRect.top = theRect->top + 10;
  203.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  204.                 iconRect.bottom = iconRect.top + 32;
  205.                 iconRect.right = iconRect.left + 32;
  206.                 
  207.                 
  208.                 // draw the icon
  209.                 if (theCellContents.iconSuiteHandle != nil)
  210.                     PlotIconSuite(&iconRect,
  211.                             ttNone, (select) ? ttSelected: ttNone,
  212.                             theCellContents.iconSuiteHandle);
  213.                             
  214.                 // Get the general area under the icon in which to draw the label
  215.                 iconRect.left = theRect->left + 2;
  216.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  217.                 iconRect.top = iconRect.bottom + 2;
  218.                 iconRect.bottom = theRect->bottom;
  219.     
  220.                 // use a nice small font for the label            
  221.                 TextFont(applFont);
  222.                 TextSize(9);
  223.                 
  224.                 {
  225.                     short        labelWidth;
  226.                     short        rectWidth;
  227.                     short        labelHeight;
  228.                     FontInfo    theInfo;
  229.                 
  230.                     // Get rid of any text that was there before
  231.                     EraseRect(&iconRect);
  232.                     iconRect.top += 2;
  233.                     
  234.                     // compute the height of the label                    
  235.                     GetFontInfo(&theInfo);
  236.                     labelHeight = theInfo.ascent + theInfo.leading;
  237.                     
  238.                     // compute where to draw the text
  239.                     iconRect.bottom = iconRect.top + labelHeight;
  240.                     rectWidth = iconRect.right-iconRect.left;
  241.                     
  242.                     // truncate the string to fit within the box
  243.                     TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
  244.                     
  245.                     // compute the new width of the string
  246.                     labelWidth = StringWidth(theCellContents.iconName);
  247.                     
  248.                     // center the string, draw it
  249.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  250.                     MoveTo(iconRect.left, iconRect.bottom);
  251.                     DrawString(theCellContents.iconName);
  252.                     
  253.                     if (select)
  254.                     {
  255.                         // compute right and lower edge of box bounding the text we just drew
  256.                         iconRect.right = iconRect.left + labelWidth;
  257.                         iconRect.bottom += theInfo.descent;
  258.                         
  259.                         // outset it, and invert it to select it
  260.                         InsetRect(&iconRect, -1, -1);
  261.                         BitClr(pHiliteBit, HiliteMode);
  262.                         InvertRect(&iconRect);
  263.                     }
  264.                 }
  265.                     
  266.                 TextFont(applFont);
  267.                 TextSize(0);
  268.             }
  269.             else
  270.             {
  271.                 // how boring!  It's only text
  272.                 FontInfo    theInfo;
  273.                 Rect        ourRect;
  274.                 
  275.                 // add a margin to the rectangle
  276.                 ourRect = *theRect;
  277.                 ourRect.left += 3;
  278.                 
  279.                 // erase the rectangle
  280.                 GetFontInfo(&theInfo);
  281.                 EraseRect(theRect);
  282.                 MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
  283.                                 
  284.                 // those darn other languages!
  285.                 if (GetSysJust() == teJustRight)
  286.                     Move(ourRect.right-ourRect.left-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
  287.                     
  288.                 OldDrawText((Ptr) &theCellContents, 0, dataLen);
  289.                 
  290.                 // if selected, invert it
  291.                 if (select)
  292.                     InvertRect(theRect);
  293.             }
  294.                 
  295.             break;
  296.             
  297.     } // switch
  298.         
  299. }
  300. /* LDEF */
  301.